const concertTpl = require('../views/concert.html')
import getdata from '../models/getdata';
import Bscroll from 'better-scroll';
class RenderConcert{
    constructor(){

    }
    async render(){
        let list = (await getdata.gethome()).suggest;
        let html = template.render(concertTpl,{
            list
        })
        $('.all-content-wrap').html(html);
        let bscroll = new Bscroll('.all-content-wrap',{
            probeType:2
        });
        bscroll.scrollTo(0,-40);
        bscroll.on('scroll',function(){
            if(this.y > 20){
                //console.log(111);
                $('.head img').addClass('up');
                
            }
            let dataY = this.y - bscroll.maxScrollY;
            if(dataY < 0 ){
                $('.foot img').addClass('down');
            }
            
        })

        bscroll.on('touchEnd',function(){
            if(this.y > 20){
                console.log(this.y);
                $('.head img').attr({'src':'/assets/images/ajax-loader.gif'});
                $.ajax({
                    url:'/dm/external/gl.html?projects=599608963204,599344942924,600079819529,599351793661,598994223541,598407773642,599953694836,598372008545,599546203054,597861915474,596820819994,598780299882,178248,178583,599528383014,598105040065,599729703910,598486727918,598220215275,597650207718,598169948276,597412029727,178463,599079778706,596665112826,599061115444,598789282301,597533091053,597522012478,178532&ctl=%E9%9F%B3%E4%B9%90%E4%BC%9A'
                }).then((res) => {
                    let data =  res.suggest;
                    //console.log(data);
                    list = [...data,...list];
                    let html = template.render(concertTpl,{
                        list
                    })
                    
                    $('.all-content-list').html(html);
                    
                    bscroll.scrollTo(0,-40,200);
                    $('.head img').attr({'src':'/assets/images/arrow.png'});
                    $('.head img').removeClass('up');
                })
               
                    
               
            }
            if(this.y < 20 && this.y > -40){
                bscroll.scrollTo(0,-40);
            }
            let dataY = this.y - bscroll.maxScrollY;
            //console.log(dataY);
            if(dataY < 0){
                console.log(111);
                $('.foot img').attr({'src':'/assets/images/ajax-loader.gif'});

                $.ajax({
                    url:'/dm/external/gl.html?projects=239608963204,599344942924,600079819529,599351793661,598994223541,598407773642,599953694836,598372008545,599546203054,597861915474,596820819994,598780299882,178248,178583,599528383014,598105040065,599729703910,598486727918,598220215275,597650207718,598169948276,597412029727,178463,599079778706,596665112826,599061115444,598789282301,597533091053,597522012478,178532&ctl=%E9%9F%B3%E4%B9%90%E4%BC%9A'
                }).then((res) => {
                    let data =  res.suggest;
                    //console.log(data);
                    list = [...list,...data];
                    let html = template.render(concertTpl,{
                        list
                    })
                    
                    $('.all-content-list').html(html);
                    
                    bscroll.scrollTo(0,bscroll.maxScrollY + 40,200);
                    $('.foot img').attr({'src':'/assets/images/arrow.png'});
                    $('.foot img').removeClass('down');
                })
            }
        }) 


    }
}

export default new RenderConcert();